#pragma once

#include <stdint.h>
#include <Winsock2.h>
#include <stdio.h>
#include <string.h>

#include "../Common/MemoryPool.h"

#define MAKE_WORD( a, b ) ( ( a << 4 ) | b )

enum Packet_Type { Packet, HeartBeat, Authenticate, Request };

union _address
{
	uint32_t addr;
	uint8_t a_bytes[4];
};

class packet
{
	public:
		packet( uint32_t src, uint32_t dst );
		virtual ~packet();
		char *serialize();
		inline void init( uint32_t src, uint32_t dst ) { source.addr = src; destination.addr = dst; }
		uint32_t getType() const { return _type; }
		uint32_t getSrc() const { return source.addr; }
		uint32_t getDst() const { return destination.addr; }
		virtual void print();
		static uint32_t VERSION;
		static uint32_t PACKET_HEADER_SIZE;
		void memory_stats() { if( buffer_pool ) buffer_pool->print(); }
		virtual void destroy() { }
	protected:
		packet( uint32_t src, uint32_t dst, Packet_Type type );
		union _address source;
		union _address destination;
		Packet_Type _type;
		static MemoryPool<char> *buffer_pool;
		static uint32_t packet_count;
		char *curbuf;
};

